<template>
  <div class="app-container">
    <div class="app-form">
      <ele-form
        v-model="formData"
        v-bind="formConfig"
        :request-fn="handleRequest"
        @request-success="handleRequestSuccess"
      />
    </div>
  </div>
</template>

<script>
import { regionCreate } from '@projectName/views/diandi_place/api/place/region'
export default {
  data() {
    return {
      formData: {
        status: 1
      },
      formConfig: {
        formDesc: {
          blocs: {
            type: 'cascader-bloc-store',
            label: '选择楼栋'
          },
          code: {
            type: 'input',
            label: 'Code'
          },
          first: {
            type: 'input',
            label: 'First'
          },
          lat: {
            type: 'input',
            label: 'Lat'
          },
          level: {
            type: 'input',
            label: 'Level'
          },
          lng: {
            type: 'input',
            label: 'Lng'
          },
          merger_name: {
            type: 'input',
            label: 'Merger Name'
          },
          name: {
            type: 'input',
            label: 'Name'
          },
          pid: {
            type: 'input',
            label: 'Pid'
          },
          pinyin: {
            type: 'input',
            label: 'Pinyin'
          },
          shortname: {
            type: 'input',
            label: 'Shortname'
          },
          zip_code: {
            type: 'input',
            label: 'Zip Code'
          }
        },
        order: []
      }
    }
  },
  methods: {
    handleRequest(data) {
      data.bloc_id = data.blocs[0]
      data.store_id = data.blocs[1]
      regionCreate(data).then((response) => {
        if (response.code === 200) {
          this.$message.success(response.message)
          this.closePage()
        } else {
          this.$message.error(response.message)
        }
      })
      return Promise.resolve()
    },
    handleRequestSuccess() {},
    closePage() {
      this.$store.dispatch('app/closePage', {
        vm: this,
        fromName: this.$route.name,
        toName: 'diandi-place-place-region-index',
        params: {}
      })
    }
  }
}
</script>
